package cn.ruituo.adv9;

import java.util.ArrayList;
import java.util.List;

public class Book2Test {
    public static void main(String[] args) {
        List<Book2> list = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            Book2 b1= new Book2(i, "java核心第" + i + "卷", "邮电出版社", 30 + i);
            for(int j=1;j<=3;j++) {
                b1.getAuthors().add(new Author("Cao "+j,20+j,"第"+j+"副教授"));
            }
            list.add(b1);
        }

        //集合转换成json
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < list.size(); i++) {
            Book2 b = list.get(i);
            sb.append("{");
            sb.append("\"id\"");
            sb.append(":");
            sb.append(b.getId());
            sb.append(",");
            sb.append("\"name\":");
            sb.append("\"" + b.getName() + "\"");

            sb.append(",");
            sb.append("\"publish\":");
            sb.append("\"" + b.getPublish() + "\"");



            sb.append(",");
            sb.append("\"price\":");
            sb.append( b.getPrice() );
            sb.append("}");

            if (i < list.size() - 1)
                sb.append(",");
        }

        sb.append("]");
        System.out.println(sb);
    }
}
